package com.jiantong.web.controller.user;

import com.jiantong.user.model.Contact;
import com.jiantong.user.service.ContactReadService;
import com.jiantong.user.service.ContactWriteService;
import io.terminus.boot.rpc.common.annotation.RpcConsumer;
import io.terminus.common.exception.JsonResponseException;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 联系人信息API
 * Created by songrenfei on 17/2/17
 */
@Slf4j
@RestController
public class Contacts {

    @RpcConsumer
    private ContactReadService contactReadService;
    @RpcConsumer
    private ContactWriteService contactWriteServicel;


    //根据主键id获取联系人信息
    @RequestMapping(value = "/api/jiantong/contact/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Contact findDeliverCompanyInfo(@PathVariable(value = "id") Long contactId){

        Response<Contact> response = contactReadService.findById(contactId);
        if(!response.isSuccess()){
            log.error("find contact by id:{} fail,error:{}",contactId,response.getError());
            throw new JsonResponseException(response.getError());
        }

        return response.getResult();

    }






}
